package com.example.drawerdemo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.content_layout.*

class MainActivity : AppCompatActivity() {

    //配置抽屉上的控制条(list,pager,text三个按键）
    private lateinit var appBarConfiguration: AppBarConfiguration
    //配置导航控制器
    private lateinit var navController: NavController

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        //设置重新定义的标题栏
        setSupportActionBar(toolbar)
        // 获得导航的实例
        navController = findNavController(R.id.fragment)
        //appBarConfiguration = AppBarConfiguration(navController.graph,drawerLayout)
        val set = setOf(R.id.textFragment,R.id.listFragment,R.id.pagerFragment)
        appBarConfiguration = AppBarConfiguration(set,drawerLayout)
        setupActionBarWithNavController(navController,appBarConfiguration)
        navigationView.setupWithNavController(navController)
    }

    override fun onSupportNavigateUp(): Boolean {
        return super.onSupportNavigateUp() || navController.navigateUp(appBarConfiguration)
    }
}
